package com.jzo2o.orders.manager.client;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jzo2o.api.customer.AddressBookApi;
import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 调用customer的客户端类
 * 客户端中心服务保护组件类
 *
 * @Author mr.lin
 * @Date 2025/1/22 17:17
 */
@Component
@Slf4j
public class CustomerClient {


    @Autowired
    private AddressBookApi addressBookApi;


    @SentinelResource(value = "findAddressDetailById", fallback = "findAddressDetailByIdFallback", blockHandler = "findAddressDetailByIdBlockHandler")
    public AddressBookResDTO findAddressDetailById(Long id) {
        log.info("客户端调用的方法走了");
        return addressBookApi.getAddressBookById(id);
    }


    //执行异常走
    public AddressBookResDTO findAddressDetailByIdFallback(Long id, Throwable throwable) {
        log.error("非限流、熔断等导致的异常执行的降级方法，id:{},throwable:", id, throwable);
        return null;
    }

    //熔断后的降级逻辑
    public AddressBookResDTO findAddressDetailByIdBlockHandler(Long id, BlockException blockException) {
        log.error("触发限流、熔断时执行的降级方法，id:{},blockException:", id, blockException);
        return null;
    }
}







